class Solution {
public:
    long long maxKelements(vector<int>& nums, int k) {
        priority_queue<int>q;
        for (auto x : nums) {
            q.push(x);
        }
        long long ans = 0;
        int cnt = 0;
        while (q.size()) {
            int t = q.top();
            q.pop();
            ans += t;
            int x = (t + 2) / 3;
            q.push(x);
            cnt++;
            if (cnt == k)break;
        }
        return ans;
    }
};